package cn.shangqizhenshuai.sqiot.action;

import cn.shangqizhenshuai.sqiot.Serivce.AreaService;
import cn.shangqizhenshuai.sqiot.entity.Area;
import cn.shangqizhenshuai.sqiot.entity.AreaExample;
import cn.shangqizhenshuai.sqiot.mapper.AreaMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("area")
public class AreaAction {
    @Autowired
    private AreaService areaService;

    /**
     * <p>查询所有区域信息</p>
     */
    @ResponseBody
    @RequestMapping("/getlist")
    public Map getlist(){
        List<Area> selectall = areaService.getlist();
        HashMap<String, Object> stringBooleanHashMap = new HashMap<String, Object>();
        stringBooleanHashMap.put("data",selectall);
        return stringBooleanHashMap;
    }

    /**
     * 增加区域
     * @param name
     * @return
     */
    @ResponseBody
    @RequestMapping("/add")
    public Map add(String name){
        int insert = areaService.add(name);
        HashMap<String, Object> stringBooleanHashMap = new HashMap<String, Object>();
        if(insert!=0){
            stringBooleanHashMap.put("data",true);
        }else{
            stringBooleanHashMap.put("data",false);
        }
        return stringBooleanHashMap;
    }

    /**
     * 删除区域
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("/del")
    public Map del(int id){
        int deli = areaService.del(id);
        HashMap<String, Object> stringBooleanHashMap = new HashMap<String, Object>();
        if(deli!=0){
            stringBooleanHashMap.put("data",true);
        }else{
            stringBooleanHashMap.put("data",false);
        }
        return stringBooleanHashMap;
    }


}
